home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1999 May / Cd Pc Users extra 20 mayo 1999.iso / Internet / UDF.BAS < prev    next >
Encoding:
BASIC Source File  |  1995-07-25  |  13.9 KB  |  516 lines

  1. Option Explicit
  2. Declare Function GetWindowsDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  3. Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  4. Declare Function MciExecute Lib "MMSystem" (ByVal CommandString As String) As Integer
  5. Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Integer) As Integer
  6. Global Const WM_USER = &H400
  7. Global Const LB_RESET = (WM_USER + 5)
  8. Global Const LB_SETHEXT = (WM_USER + 21)
  9. Global Const LB_GETHEXT = (WM_USER + 20)
  10. Global Const LB_GETITEMH = (WM_USER + 34)
  11. Declare Function SetCapture Lib "User" (ByVal hWnd As Integer) As Integer
  12. Declare Sub ReleaseCapture Lib "User" ()
  13. Type RECT
  14.     Left As Integer
  15.     Top As Integer
  16.     right As Integer
  17.     bottom As Integer
  18. End Type
  19. Declare Sub ClipCursor Lib "User" (lpRect As Any)
  20. Declare Sub GetClientRect Lib "User" (ByVal hWnd As Integer, lpRect As RECT)
  21. Declare Function GetActiveWindow Lib "User" () As Integer
  22. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  23. Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Long) As Integer
  24. Global Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
  25. Type PointApi
  26.      X As Integer
  27.      Y As Integer
  28. End Type
  29. Declare Sub GETCURSORPOS Lib "User" (lpPoint As PointApi)
  30. Declare Function sndPlaySound Lib "MMSYSTEM.DLL" (ByVal lpszSoundName$, ByVal Wflags%) As Integer
  31. Global Const SND_SYNC = &H0
  32. Global Const SND_ASYNC = &H1
  33. Global Const SND_NODEFAULT = &H2
  34. Global Const SND_LOOP = &H8
  35. Global Const SND_NOSTOP = &H10
  36. Global V_Reng() As String
  37. Declare Function SetSysModalWindow Lib "User" (ByVal hWnd%) As Integer
  38. Global WPath$
  39.  
  40. Sub AjustaImg (Img As Image, Arch As String, X As Integer, Y As Integer, AN As Integer, AL As Integer)
  41.     Dim ANP%, ALP%, FACX, FACY
  42.     Img.Visible = False
  43.     Img.Stretch = False
  44.     Img.Picture = LoadPicture(Arch)
  45.     ANP = Img.Width
  46.     ALP = Img.Height
  47.     Img.Stretch = True
  48.     FACX = AN / ANP
  49.     FACY = AL / ALP
  50.     If FACX > FACY Then
  51.     FACX = FACY
  52.     Else
  53.     FACY = FACX
  54.     End If
  55.     Img.Width = (ANP * FACX)
  56.     Img.Height = (ALP * FACY)
  57.     Img.Left = X + (AN - Img.Width) / 2
  58.     Img.Top = Y + (AL - Img.Height) / 2
  59.     'Img.Visible = True
  60. End Sub
  61.  
  62. Sub AjustaImgFX (Img As Control, Arch As String, X As Integer, Y As Integer, AN As Integer, AL As Integer, ImgDummy As Control)
  63.     Dim ANP%, ALP%, FACX, FACY, WTag$
  64.     Img.FileName = ""
  65.     Img.Visible = True
  66.     Img.AutoSize = 1
  67.     Img.FileName = Arch
  68.     Img.Refresh
  69.     Img.Visible = False
  70.     'ImgDummy.Visible = False
  71.     'ImgDummy.Stretch = False
  72.     'ImgDummy.Picture = LoadPicture(Arch)
  73.     ANP = Img.Width
  74.     ALP = Img.Height
  75.     Img.FileName = ""
  76.     'ImgDummy.Picture = LoadPicture()
  77.     WTag = "T:" + Trim(Str$(FileLen(Arch)))
  78.     WTag = WTag + "/" + "H:" + Trim(Str$(ALP))
  79.     WTag = WTag + "/" + "W:" + Trim(Str$(ANP))
  80.     Img.Tag = WTag
  81.     'Img.Stretch = True
  82.     FACX = AN / ANP
  83.     FACY = AL / ALP
  84.     If FACX > FACY Then
  85.     FACX = FACY
  86.     Else
  87.     FACY = FACX
  88.     End If
  89.     Img.Width = (ANP * FACX)
  90.     Img.Height = (ALP * FACY)
  91.     Img.Left = X + (AN - Img.Width) / 2
  92.     Img.Top = Y + (AL - Img.Height) / 2
  93.     'Img.Refresh
  94.     Img.AutoSize = 2
  95.     'Img.Picture = LoadPicture(Arch)
  96.     Img.FileName = Arch
  97.     'Img.Visible = True
  98. End Sub
  99.  
  100. Sub Alinear (Cual As Control, Concual As Control)
  101.     Cual.Top = Concual.Top
  102.     Cual.Left = Concual.Left
  103. End Sub
  104.  
  105. Sub Center (quien As Control)
  106.     quien.Height = 480
  107.     quien.Width = 640
  108.     quien.Top = (screen.Height / screen.TwipsPerPixelY - quien.Height) / 2
  109.     quien.Left = (screen.Width / screen.TwipsPerPixelX - quien.Width) / 2
  110. End Sub
  111.  
  112. Sub CenterSize (quien As Control)
  113.     quien.Top = (screen.Height / screen.TwipsPerPixelY - quien.Height) / 2
  114.     quien.Left = (screen.Width / screen.TwipsPerPixelX - quien.Width) / 2
  115. End Sub
  116.  
  117. Sub CopiaFon (Source As PictureBox, Dest As PictureBox)
  118.     Dim A As Integer
  119.     Dim A1%, A2%
  120.     A1 = Source.AutoRedraw
  121.     A2 = Dest.AutoRedraw
  122.     Source.AutoRedraw = True
  123.     Dest.AutoRedraw = True
  124.     A = BitBlt(Dest.hDC, 0, 0, Dest.Width, Dest.Height, Source.hDC, Dest.Left, Dest.Top, SRCCOPY)
  125.     Source.AutoRedraw = A1
  126.     Dest.AutoRedraw = A2
  127. End Sub
  128.  
  129. Sub CopiaPic (Source As PictureBox, Dest As PictureBox)
  130.     Dim A As Integer
  131.     Dim A1, A2
  132.     A1 = Source.AutoRedraw
  133.     A2 = Dest.AutoRedraw
  134.     Source.AutoRedraw = True
  135.     Dest.AutoRedraw = True
  136.     A = BitBlt(Dest.hDC, 0, 0, Source.Width, Source.Height, Source.hDC, 0, 0, SRCCOPY)
  137.     Source.AutoRedraw = A1
  138.     Dest.AutoRedraw = A2
  139. End Sub
  140.  
  141. Function DirWin () As String
  142.     Dim WinDir$, I%
  143.     WinDir$ = Space$(144)
  144.     I = GetWindowsDirectory(WinDir$, 144)
  145.     If I = 0 Then
  146.     DirWin = ""
  147.     Else
  148.     WinDir$ = TTrim$(WinDir$)
  149.     If Right(WinDir$, 1) <> "\" Then
  150.     WinDir$ = WinDir$ + "\"
  151.     End If
  152.     DirWin = WinDir$
  153.     End If
  154. End Function
  155.  
  156. Function DirWinS () As String
  157.     Dim WinSysDir$, I%
  158.     WinSysDir$ = Space$(144)
  159.     I = GetSystemDirectory(WinSysDir$, 144)
  160.     If I = 0 Then
  161.     DirWinS = ""
  162.     Else
  163.     WinSysDir$ = TTrim$(WinSysDir$)
  164.     If Right(WinSysDir$, 1) <> "\" Then
  165.         WinSysDir$ = WinSysDir$ + "\"
  166.     End If
  167.     DirWinS = WinSysDir$
  168.     End If
  169. End Function
  170.  
  171. Sub DividirTXT (Wtext As String, Crengs As Integer, ThePicture As PictureBox, Offset As Integer)
  172.     Dim StringtoPrint As String
  173.     Dim NextWord As String
  174.     Dim AcLength As Integer
  175.     Dim X As Integer
  176.     ThePicture.CurrentX = Offset
  177.     ThePicture.CurrentY = Offset
  178.     ReDim V_Reng(1)
  179.     StringtoPrint = Wtext
  180.     AcLength = Offset
  181.     NextWord = SacaPal(StringtoPrint)
  182.     X = 1
  183.     Do While NextWord <> ""
  184.     If ((AcLength + ThePicture.TextWidth(NextWord)) > ThePicture.ScaleWidth) Then
  185.         X = X + 1
  186.         ReDim Preserve V_Reng(X)
  187.         AcLength = Offset + ThePicture.TextWidth(NextWord)
  188.       Else
  189.         AcLength = AcLength + ThePicture.TextWidth(NextWord)
  190.     End If
  191.     If Left$(NextWord, 2) = Chr$(10) + Chr$(13) Or Left$(NextWord, 2) = Chr$(13) + Chr$(10) Then
  192.         X = X + 1
  193.         ReDim Preserve V_Reng(X)
  194.         NextWord = Mid$(NextWord, 3)
  195.         AcLength = Offset + ThePicture.TextWidth(NextWord)
  196.     End If
  197.     V_Reng(X) = V_Reng(X) + NextWord
  198.     NextWord = SacaPal(StringtoPrint)
  199.     Loop
  200.     X = X + 1
  201.     ReDim Preserve V_Reng(X)
  202.     V_Reng(X) = "~EOF~"
  203.     Crengs = X - 1
  204. End Sub
  205.  
  206. Sub Emilinea (Texto As String, Pic As PictureBox, Reng As Integer, Col As Long, Offs As Integer)
  207.     Dim X As Integer
  208.     Dim Cant As Long
  209.     Pic.CurrentX = 0
  210.     Pic.CurrentY = 0
  211.     For X = 1 To Reng - 1
  212.     Pic.Print
  213.     Next X
  214.     Cant = Pic.ForeColor
  215.     Pic.ForeColor = Col
  216.     Pic.CurrentX = Offs
  217.     Pic.Print Texto
  218.     Pic.ForeColor = Cant
  219. End Sub
  220.  
  221. Function FMes (Cual) As String
  222.     Select Case Cual
  223.     Case 1
  224.         FMes = "Enero"
  225.     Case 2
  226.         FMes = "Febrero"
  227.     Case 3
  228.         FMes = "Marzo"
  229.     Case 4
  230.         FMes = "Abril"
  231.     Case 5
  232.         FMes = "Mayo"
  233.     Case 6
  234.         FMes = "Junio"
  235.     Case 7
  236.         FMes = "Julio"
  237.     Case 8
  238.         FMes = "Agosto"
  239.     Case 9
  240.         FMes = "Septiembre"
  241.     Case 10
  242.         FMes = "Octubre"
  243.     Case 11
  244.         FMes = "Noviembre"
  245.     Case 12
  246.         FMes = "Diciembre"
  247.     End Select
  248. End Function
  249.  
  250. Function FWPath () As String
  251.     Dim WPath$
  252.     WPath = app.Path
  253.     If Right$(WPath, 1) <> "\" Then
  254.     WPath = WPath + "\"
  255.     End If
  256.     FWPath = WPath
  257. End Function
  258.  
  259. Sub PlaySnd (Cual As String)
  260.     Dim A%, Wflags%
  261.     Wflags% = SND_ASYNC Or SND_NODEFAULT
  262.     A% = sndPlaySound(Cual, Wflags%)
  263. End Sub
  264.  
  265. Sub PlaySndNS (Cual As String)
  266.     Dim A%, Wflags%
  267.     Wflags% = SND_SYNC Or SND_NODEFAULT
  268.     A% = sndPlaySound(Cual, Wflags%)
  269. End Sub
  270.  
  271. Sub PlaySndR (Cual As String)
  272.     Dim A%, Wflags%
  273.     Wflags% = SND_ASYNC Or SND_NODEFAULT Or SND_LOOP
  274.     A% = sndPlaySound(Cual, Wflags%)
  275. End Sub
  276.  
  277. Sub PrCenter (Wstr As String, Pic As PictureBox, Reng As Integer, Col As Long)
  278.     Dim X As Integer, L%
  279.     Dim Cant As Long
  280.     Pic.CurrentX = 0
  281.     Pic.CurrentY = 0
  282.     For X = 1 To Reng - 1
  283.     Pic.Print
  284.     Next X
  285.     Cant = Pic.ForeColor
  286.     Pic.ForeColor = Col
  287.     L = Pic.TextWidth(Wstr)
  288.     X = Int((Pic.ScaleWidth - L) / 2)
  289.     Pic.CurrentX = X
  290.     Pic.Print Wstr
  291.     Pic.ForeColor = Cant
  292. End Sub
  293.  
  294. Sub PrintPic (Texto As String, ThePicture As PictureBox, OffSetX As Integer, OffSetY As Integer, MX%, MY%)
  295.     Dim StringtoPrint As String
  296.     Dim NextWord As String
  297.     Dim AcLength As Integer
  298.     StringtoPrint = Texto
  299.     ThePicture.Cls
  300.     ThePicture.CurrentX = OffSetX
  301.     ThePicture.CurrentY = OffSetY
  302.     If MX = 0 Then
  303.     MX = ThePicture.ScaleWidth
  304.     End If
  305.     If MY = 0 Then
  306.     MY = ThePicture.ScaleHeight
  307.     End If
  308.     AcLength = OffSetX
  309.     NextWord = SacaPal(StringtoPrint)
  310.     Do While NextWord <> ""
  311.     If ((AcLength + ThePicture.TextWidth(NextWord)) > MX) Then
  312.         ThePicture.Print
  313.         ThePicture.CurrentX = OffSetX
  314.         AcLength = OffSetX + ThePicture.TextWidth(NextWord)
  315.       Else
  316.         AcLength = AcLength + ThePicture.TextWidth(NextWord)
  317.     End If
  318.     Do While Left$(NextWord, 2) = Chr$(10) + Chr$(13) Or Left$(NextWord, 2) = Chr$(13) + Chr$(10)
  319.         ThePicture.Print
  320.         If ThePicture.CurrentY > MY Then
  321.         Exit Sub
  322.         End If
  323.         ThePicture.CurrentX = OffSetX
  324.         NextWord = Mid$(NextWord, 3)
  325.         AcLength = OffSetX + ThePicture.TextWidth(NextWord)
  326.     Loop
  327.     ThePicture.Print NextWord;
  328.     NextWord = SacaPal(StringtoPrint)
  329.     Loop
  330. End Sub
  331.  
  332. Sub PrintPicP (Texto As String)
  333.     Dim StringtoPrint As String
  334.     Dim NextWord As String
  335.     Dim AcLength As Integer
  336.     Dim Offset%
  337.     StringtoPrint = Texto
  338.     Offset = 0
  339.     Printer.CurrentX = Offset
  340.     Printer.CurrentY = Offset
  341.     AcLength = Offset
  342.     NextWord = SacaPal(StringtoPrint)
  343.     Do While NextWord <> ""
  344.     If ((AcLength + Printer.TextWidth(NextWord)) > Printer.ScaleWidth) Then
  345.         Printer.Print
  346.         Printer.CurrentX = Offset
  347.         AcLength = Offset + Printer.TextWidth(NextWord)
  348.       Else
  349.         AcLength = AcLength + Printer.TextWidth(NextWord)
  350.     End If
  351.     If Left$(NextWord, 2) = Chr$(10) + Chr$(13) Or Left$(NextWord, 2) = Chr$(13) + Chr$(10) Then
  352.         Printer.Print
  353.         Printer.CurrentX = Offset
  354.         NextWord = Mid$(NextWord, 3)
  355.         AcLength = Offset + Printer.TextWidth(NextWord)
  356.     End If
  357.     Printer.Print NextWord;
  358.     NextWord = SacaPal(StringtoPrint)
  359.     Loop
  360. End Sub
  361.  
  362. Sub PrintPicR (PR As Integer, CR As Integer, ThePicture As PictureBox, Offset As Integer)
  363.     Dim X As Integer
  364.     ThePicture.Cls
  365.     ThePicture.CurrentY = Offset
  366.     For X = PR To PR + CR - 1
  367.     If V_Reng(X) = "~EOF~" Then
  368.         Exit For
  369.     End If
  370.     ThePicture.CurrentX = Offset
  371.     ThePicture.Print V_Reng(X)
  372.     Next X
  373. End Sub
  374.  
  375. Function SacaPal (AnyString As String) As String
  376.     Dim WRet$, Wenter$, P1%, P2%, Pos%, Espacio%
  377.     Wenter$ = Chr(13) + Chr(10)
  378.     P2 = InStr(AnyString, " ")
  379.     P1 = InStr(AnyString, Wenter)
  380.     If P1 = P2 Then
  381.     WRet = AnyString
  382.     AnyString = ""
  383.     Else
  384.     If P2 < P1 Then
  385.         Espacio = (P2 <> 0)
  386.     Else
  387.         Espacio = (P1 = 0)
  388.     End If
  389.     If Not Espacio Then 'Primero el <Enter>
  390.         If P1 = 1 Then
  391.         WRet = Wenter$
  392.         AnyString = Mid$(AnyString, 3)
  393.         Else
  394.         WRet = Left$(AnyString, P1 - 1)
  395.         AnyString = Mid$(AnyString, P1)
  396.         End If
  397.     Else
  398.         WRet = Left$(AnyString, P2)
  399.         AnyString = Mid$(AnyString, P2 + 1)
  400.     End If
  401.     End If
  402.     SacaPal = WRet
  403. End Function
  404.  
  405. Function Sinext (DeQue As String) As String
  406.     Dim N%
  407.     N% = InStr(DeQue, ".")
  408.     If N% = 0 Then
  409.     Sinext = Trim$(DeQue)
  410.     Else
  411.     Sinext = Left$(Trim$(DeQue), N - 1)
  412.     End If
  413. End Function
  414.  
  415. Function SinPath (WDeQue$) As String
  416.     Dim WRet$, L$, P, DeQue$
  417.     DeQue = Trim$(WDeQue)
  418.     If Right(WDeQue, 1) = "\" Then
  419.     WDeQue = Left(WDeQue, Len(WDeQue) - 1)
  420.     End If
  421.     WRet = ""
  422.     P = Len(DeQue)
  423.     Do While P <> 0
  424.     L = Mid$(DeQue, P, 1)
  425.     If L = "\" Then
  426.         WRet = Mid(DeQue, P + 1)
  427.         Exit Do
  428.     End If
  429.     P = P - 1
  430.     Loop
  431.     SinPath = WRet
  432. End Function
  433.  
  434. Function StrTr (AQue$, Que$, ConQue$) As String
  435.     Dim WRet$, P%
  436.     WRet$ = AQue$
  437.     P = InStr(1, WRet$, Que$)
  438.     Do Until P = 0
  439.     WRet$ = Left$(WRet$, P - 1) + ConQue$ + Mid$(WRet$, P + Len(Que$))
  440.     P = P + Len(Que$)
  441.     P = InStr(P, WRet$, Que$)
  442.     Loop
  443.     StrTr = WRet$
  444. End Function
  445.  
  446. Function StrTran (Inp As String, Cual As String, Concual As String) As String
  447.     Dim C$, X%, L%, WRet$
  448.     WRet$ = ""
  449.     L% = Len(Inp$)
  450.     For X = 1 To L%
  451.     C = Mid$(Inp, X, 1)
  452.     If C = Cual Then
  453.         WRet$ = WRet$ + Concual
  454.     Else
  455.         WRet$ = WRet$ + C
  456.     End If
  457.     Next
  458.     StrTran = WRet
  459. End Function
  460.  
  461. Function Truncado (QueStr As String, Pbox As Control, Longi As Integer) As String
  462.     Dim N%, WRet$, L%, Pala$, Orig$
  463.     WRet$ = ""
  464.     If Pbox.TextWidth(Trim$(QueStr)) < Longi Then
  465.     Truncado = Trim$(QueStr)
  466.     Else
  467.     Orig$ = QueStr
  468.     N = Longi - Pbox.TextWidth("...") - 2
  469.     L% = 0
  470.     Pala = ""
  471.     Do While L% < N%
  472.         WRet = WRet + Pala
  473.         Pala = SacaPal(Orig)
  474.         L = Pbox.TextWidth(Trim(WRet + Pala))
  475.     Loop
  476.     WRet = Trim(WRet) + "..."
  477.     Truncado = WRet
  478.     End If
  479. End Function
  480.  
  481. Function TTrim$ (Incoming$)
  482.     Dim Temp$, I%
  483.     Temp$ = Incoming$
  484.     I% = InStr(Temp$, Chr$(0))
  485.     If I% <> 0 Then
  486.     Temp$ = Left$(Temp$, I% - 1)
  487.     End If
  488.     Temp$ = LTrim$(RTrim$(Temp$))
  489.     TTrim$ = Temp$
  490. End Function
  491.  
  492. Function Unif (Loque As String) As String
  493.     Unif = RTrim$(LTrim$(UCase$(Loque)))
  494. End Function
  495.  
  496. Function ValidPath (DeQue$) As String
  497.     Dim WRet$, P%, Aux$, K%, L$
  498.     Aux = DeQue
  499.     P = InStr(3, Aux, "\..")
  500.     Do While P <> 0
  501.     If P <> 1 Then
  502.         K = P
  503.         L$ = Mid(Aux, K - 1, 1)
  504.         Do While L <> "\"
  505.         K = K - 1
  506.         L$ = Mid(Aux, K, 1)
  507.         Loop
  508.         Aux = Left(Aux, K - 1) + Mid$(Aux, P + 3)
  509.     End If
  510.     P = InStr(3, Aux, "\..")
  511.     Loop
  512.     WRet = Aux
  513.     ValidPath = WRet
  514. End Function
  515.  
  516.